/*
 * Choose Service Units to Log dialog.
 * Called when "Specify Service Unit Logging" button is clicked in Logging configuration for deployment
 * Created  by Bench, June 2007
 */

if(!jsx3.lang.Class.forName("tibco.admin.deployment.sa.logCfg.LogCfg")) {

    jsx3.lang.Class.defineClass(
            "tibco.admin.deployment.sa.logCfg.LogCfg", // full name of the class to create
            null,
            null,
            function(service) {          //name the argument of this function

                service.block = null;

                service.subscribed = false;
                // prevent from subscribing twice

                service.callgetAllServiceUnitsSummary = function(objEvent) {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/deployment/sa/su/sulist/rules/getAllServiceUnitsSummaryRule.xml", "getAllServiceUnitsSummary");
                    objService.saEntityID = objEvent.entityID;
                    // service assembly id
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getDeploymentEndpointURL());

                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, service.ongetAllServiceUnitsSummarySuccess);
                    objService.doCall();
                };

                service.ongetAllServiceUnitsSummarySuccess = function(objEvent) {
                    service.block.loader.selectExistingServiceUnit();
                    service.block.loader.toggleSelectAllCheckbox(1);
                    // check this box if all service units are selected.
                    service.block.getDescendantOfName("mtxChooseSU_49").repaintData();
                };

                service.doClose = function(obj) {
                    obj.getAncestorOfType(jsx3.gui.Dialog).doClose();
                }

                service.onSave = function(obj) {
                    service.block.loader.btnSave_DLG_onclick();
                }

                service.subscribeAll = function() {
                    if(!service.subscribed) {
                        tibco.admin.PubSub.subscribe(tibco.admin.deployment.saList.EventID.SERVICEASSEMBLY_ROW_SELECTED, service.callgetAllServiceUnitsSummary);
                        service.subscribed = true;
                    }
                }

                service.unsubscribeAll = function() {
                    if(service.subscribed) {
                        tibco.admin.PubSub.unsubscribe(tibco.admin.deployment.saList.EventID.SERVICEASSEMBLY_ROW_SELECTED, service.callgetAllServiceUnitsSummary);
                        service.subscribed = false;
                    }
                }

                service.onAfterDeserialize = function(objJSX) {
                    service.block = objJSX;
                    service.subscribeAll();
                }

                service.onDestroy = function() {
                    service.unsubscribeAll();
                    service.block.loader = null;
                    service.block = null;
                }

            }
            );

}
